package com.atguigu.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.entity.*;
import com.atguigu.result.RetVal;
import com.atguigu.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author ：Hachimen
 * @date ：Created in 2021/8/21 11:59
 * @description：BaseCategory控制类
 * @modified By：
 * @version: 0.0.1
 */
@RestController
@RequestMapping("product")
//@CrossOrigin
public class BaseCategoryController {
    @Autowired
    private BaseCategory1Service baseCategory1Service;

    @Autowired
    private BaseCategory2Service baseCategory2Service;

    @Autowired
    private BaseCategory3Service baseCategory3Service;

    @Autowired
    private BaseCategoryViewService baseCategoryViewService;



    // 获取一级分类数据
    @GetMapping("getCategory1")
    public RetVal getCategory1() {
        List<BaseCategory1> category1List = baseCategory1Service.list(null);
        return RetVal.ok(category1List);
    }

    // 获取二级分类数据
    @GetMapping("getCategory2/{baseCategory1Id}")
    public RetVal getCategory2(@PathVariable Long baseCategory1Id) {
        QueryWrapper<BaseCategory2> wrapper = new QueryWrapper<>();
        wrapper.eq("category1_id",baseCategory1Id);
        List<BaseCategory2> category2List = baseCategory2Service.list(wrapper);
        return RetVal.ok(category2List);
    }

    // 获取三级分类数据
    @GetMapping("getCategory3/{baseCategory2Id}")
    public RetVal getCategory3(@PathVariable Long baseCategory2Id) {
        QueryWrapper<BaseCategory3> wrapper = new QueryWrapper<>();
        wrapper.eq("category2_id",baseCategory2Id);
        List<BaseCategory3> category3List = baseCategory3Service.list(wrapper);
        return RetVal.ok(category3List);
    }

    //获取首页分类json
    @GetMapping("getIndexCategoryInfo")
    public RetVal getIndexCategoryInfo(){
        List<JSONObject> list = baseCategoryViewService.getIndexCategoryInfo();
        return RetVal.ok(list);
    }





    }